package cn.xiaou.view;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import cn.xiaou.utils.ImageManagerUtils;
    
public class MainView extends JPanel {    
    
    private static final long serialVersionUID = 1L;    
    
    private JPanel webBrowserPanel;    
    
    private JWebBrowser webBrowser;    
    
    private String url;    
    
	public MainView(String url) { 
        super(new BorderLayout());    
        this.url = url;    
        webBrowserPanel = new JPanel(new BorderLayout());   
        webBrowser = new JWebBrowser();    
        webBrowser.navigate(url);    
        webBrowser.setButtonBarVisible(false);    
        webBrowser.setMenuBarVisible(false);    
        webBrowser.setBarsVisible(false);    
        webBrowser.setStatusBarVisible(false);    
        webBrowserPanel.add(webBrowser, BorderLayout.CENTER);   
        add(webBrowserPanel, BorderLayout.CENTER);
        // webBrowser.executeJavascript("javascrpit:window.location.href='http://www.baidu.com'");  
//         webBrowser.executeJavascript("alert('haha')"); //执行Js代码  
       
    }
    
    
    public static void Browser() {    
        final String url = "http://www.zjiet.edu.cn/";    
        final String title = "欢迎";    
        UIUtils.setPreferredLookAndFeel();    
        NativeInterface.open();    
    
        SwingUtilities.invokeLater(new Runnable() {    
            public void run() {    
                JFrame frame = new JFrame(title);   
                frame.setIconImage(frame.getToolkit().getImage(ImageManagerUtils.icoUrl));
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                // frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                
                frame.getContentPane().add(new MainView(url), BorderLayout.CENTER);    
                frame.setExtendedState(JFrame.MAXIMIZED_BOTH);    
                frame.setLocationByPlatform(true);
                // KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();  
               /* manager.addKeyEventPostProcessor(new KeyEventPostProcessor() {
        			
        			@Override
        			public boolean postProcessKeyEvent(KeyEvent e) {
        				System.out.println(e.getID());
        				if(e.getID()== 401) {
        					System.out.println(1);
        					frame.setUndecorated(true);
        				}
        				return false;
        			}
        		});*/
                frame.setVisible(true);    
            }    
        });    
        //NativeInterface.runEventPump();    
    } 
    public String getUrl() {
		return url;
	}


	public void setUrl(String url) {
		this.url = url;
	}
    
}    